#include <functional>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

#include "gMockSample.h"

static std::function<int()> _toMock;
struct MyMock {
     MyMock() {
         _toMock = [this](){
             return toMock();
         };
     }
     ~MyMock() {
         _toMock = {};
     }
     MOCK_METHOD(int, toMock, ());
};

int toMock()
{
    return _toMock();
}

TEST(TesttoTest, withMock) {
    MyMock mock;
    EXPECT_CALL(mock, toMock())
        /* the original toMock returns 10
         * the mocked one returns 2
         */
        .WillRepeatedly(::testing::Return(2));

    EXPECT_EQ(toTest(7), 14);
}

